//
//  ZCBaseSettingTVC.m
//  SSMusic
//
//  Created by 张灿 on 16/4/23.
//  Copyright © 2016年 张灿. All rights reserved.
//

#import "ZCBaseSettingTVC.h"


@interface ZCBaseSettingTVC ()

@end

@implementation ZCBaseSettingTVC

- (NSMutableArray *)groupArr
{
    if (_groupArr == nil) {
        _groupArr = [NSMutableArray array];
    }
    return _groupArr;
}

//初始化时设置为组模式
- (instancetype)init {
    
    return [super initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.groupArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//取出组数组里面的行数组
    GroupItem *item = self.groupArr[section];
    return item.rowItemArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    //取出组模型
    GroupItem *groupI = self.groupArr[indexPath.section];
    //取出行模型
    accountItem *item = groupI.rowItemArr[indexPath.row];
    
    cell.textLabel.text = item.title;
    cell.imageView.image = item.image;
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

//点击行cell设置跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //取出当前的行模型
    GroupItem *groupItem = self.groupArr[indexPath.section];
    accountItem *item = groupItem.rowItemArr[indexPath.row];
    
    //判断模型的类型
    if ([item isKindOfClass:[ZCArrowItem class]]) {
        
         ZCArrowItem *arrowItem = (ZCArrowItem *)item;
        
        //判断有没有要执行的任务
        if (arrowItem.operationTask) {
            //执行任务
            arrowItem.operationTask(indexPath);
            
            return;
        }
        
        if(arrowItem.desClass) {
            //创建控制器,跳转到指定的控制器.
            UIViewController *vc = [[arrowItem.desClass alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
    
}

//设置组间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 3;
}

@end
